#ifndef MYTCPSERVER_H
    #define MYTCPSERVER_H

#pragma once
// #include <QObject>
#include <QTcpServer>
#include <QThread>
#include <QVector>
#include <QPair>

// 自写头文件
#include "ClientHandle.h"

class MyTcpServer : public QTcpServer //, public QThread
{
    Q_OBJECT

public:
    explicit MyTcpServer(QTcpServer *parent = nullptr);
    explicit MyTcpServer(qintptr socketDescriptor, QTcpServer *parent = nullptr);
    ~MyTcpServer();

    // 获取 private 成员函数
    const QVector<QPair<ClientHandle*, QThread*>> get_my_client();
    const int get_thread_count();
    const ClientInfo* get_current_message();

signals:
    void signal_to_thread();
    void send_message_to_widget_signal();
    void send_thread_count_signal();

protected:
    void incomingConnection(qintptr socketDescriptor) override;

public slots:

private slots:
    void get_client_message_slot(const ClientInfo* clint_info);

    void thread_disconnect_signal(ClientHandle* client);

private:
    QVector<QPair<ClientHandle*, QThread*>>     my_client;
    qintptr                                     my_socketDescriptor;
    ClientInfo*                                 current_message;

    // 统计连接线程数
    int thread_count;

    // std::vector<QThread*>                       client_thread;
    // std::vector<ClientHandle*>  my_client;
};

#endif // MYTCPSERVER_H
